package com.woniuxy.rms.dao;

import com.woniuxy.rms.pojo.Menus;
import com.woniuxy.rms.pojo.RoleMenu;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;
import org.springframework.web.bind.annotation.DeleteMapping;

import java.util.List;

public interface MenusMapper {
    int deleteByPrimaryKey(Integer id);

    int insert(Menus record);

    int insertSelective(Menus record);

    Menus selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(Menus record);

    int updateByPrimaryKey(Menus record);

    @Select("select * from Menus inner join role_menu r on r.menu_id = Menus.id where r.role_id = #{value}")
    List<Menus> findByRoleId(Integer roleId);

    @Select("select m.*,p.permission,a.admin_name from Menus m left join permission p on " +
            "p.id = m.permission_id left join admin a on a.id = m.admin_id")
    List<Menus> findAll();

    @Select("select * from Menus where title = #{value}")
    List<Menus> findByTitle(String title);

    @Delete("delete from Menus where id = #{value} or parent_id = #{value}")
    void deleteById(Integer id);

    /**
     * Description : 通过中间表查询角色数据  <br/>
     * ChangeLog : 1. 创建 (2020/3/25 0025 下午 4:12 [Administrator]);
     * @param roleId
     * @return java.util.List<com.woniuxy.rms.pojo.Menus>
    */
    @Select("select Menus.* from Menus inner join role_menu rm on Menus.id = rm.menu_id where rm.role_id = #{value}")
    List<Menus> findCheckMenusByRoles(Integer roleId);

    /**
     * Description : 通过权限id批量删除  <br/>
     * ChangeLog : 1. 创建 (2020/3/26 0026 上午 10:49 [Administrator]);
     * @param permIds
     * @return void
    */
    void batchDelMenuBypermIds(List<Integer> permIds);

    /**
     * Description : 通过权限id查询角色菜单中间表  <br/>
     * ChangeLog : 1. 创建 (2020/4/2 0002 下午 5:02 [Administrator]);
     * @param permIds
     * @return java.util.List<com.woniuxy.rms.pojo.RoleMenu>
    */
    List<RoleMenu> findRoleMenuByPid(List<Integer> permIds);
}